package com.tongtong.stsuserapi.controller;

import com.tongtong.stscommon.message.STSMessage;
import com.tongtong.stsuserapi.service.login.UserLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录控制器
 */
@Api(tags="登录接口")
@RestController
@RequestMapping("/sts")
public class LoginController {

	@Autowired
	private UserLoginService loginService;

	@ApiOperation("登录")
	@ApiImplicitParam(name = "username", value = "用户使用手机号登录，管理员使用用户名登录")
	@PostMapping("/login")
	public STSMessage login(String username, String password) throws Exception{
		return loginService.login(username,password);
	}

	@ApiOperation("登出")
	@PostMapping("/logout")
	@PreAuthorize("hasAnyAuthority('user','manager')")
	public STSMessage logout() {
		return loginService.logout();
	}

	@ApiOperation("判断登录状态")
	@GetMapping("/judge")
	@PreAuthorize("hasAnyAuthority('user','manager')")
	public STSMessage judge() {
		return loginService.judgeLoginStatus();
	}

}